class particle {

  float x_loc; 
  float y_loc;


  int mass; ///diameter
  float radius;

  float rotation;
  float velocity;

  boolean alive=true;

 
 
  color cc;

  particle() {
    float offset=0;
    set_mass(1);


    cc =  color(random(200,255),random(200,255),random(200,255));

    x_loc = width/2;
    y_loc = height/2;
    rotation = random(0,360);
   
    velocity = random(1,20);
  }


  void set_x() {
    x_loc = x_loc + cos(radians(rotation))*velocity ;
  }
  void set_y() {
    y_loc = y_loc + sin(radians(rotation))*velocity ;
  }


  void math() {
    if(alive) {

      clamp_to_stage();
      clamp_rotation();

      speed();

      set_x();
      set_y();
    }
  }

  void set_mass(int mass) {
    this.mass = mass;
    radius = (float)mass/2;
  }


  void speed() {
    if(mass <=4) {
      velocity = .3;

    }

    if ((mass >4) && (mass<10)) {
      velocity = .2;

    }
    else {
      if(mass>10) {
        velocity =.1;
      }
    }
  }

  void render() {
        fill(cc);
        rect(x_loc,y_loc,mass,mass);
  }

  void set_alive(boolean alive) {
    this.alive = alive;
  }

  boolean get_alive() {
    return alive;
  }

 
  void clamp_to_stage() {
    if(x_loc<0) {
      x_loc =0+velocity;
      rotation = rotation+(180-(rotation*2));
    }
    else {
      if(x_loc>width) {
        x_loc =width-velocity;
        rotation = rotation+(180-(rotation*2));
      }
    }

    if(y_loc<0) {
      y_loc =0+velocity;
      rotation = rotation-(180-(rotation*2));
    }
    else {
      if(y_loc>height) {
        y_loc =height-velocity;
        rotation = rotation-(180-(rotation*2));
      }
    }
  }

  void clamp_rotation() {
    if(rotation > 360) {
      rotation = rotation - 360;
    } 
    if(rotation < 0) {
      rotation = rotation + 360;
    }
  }

  void reset(float x_loc, float y_loc) {
    set_mass(1);
    velocity = .3;
    rotation = random(0,360);
    this.x_loc = x_loc;
    this.y_loc = y_loc;
  }
}

